home *** CD-ROM | disk | FTP | other *** search
/ Gamers Delight 2 / Gamers Delight 2.iso / Aminet / game / role / pinfocom_3_0.lha / Source / infocom.h < prev    next >
C/C++ Source or Header  |  1992-10-22  |  15KB  |  492 lines

  1. /* infocom.h
  2.  *
  3.  *  ``pinfocom'' -- a portable Infocom Inc. data file interpreter.
  4.  *  Copyright (C) 1987-1992  InfoTaskForce
  5.  *
  6.  *  This program is free software; you can redistribute it and/or modify
  7.  *  it under the terms of the GNU General Public License as published by
  8.  *  the Free Software Foundation; either version 2 of the License, or
  9.  *  (at your option) any later version.
  10.  *
  11.  *  This program is distributed in the hope that it will be useful,
  12.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  *  GNU General Public License for more details.
  15.  *
  16.  *  You should have received a copy of the GNU General Public License
  17.  *  along with this program; see the file COPYING.  If not, write to the
  18.  *  Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  */
  20.  
  21. /*
  22.  * $Header: RCS/infocom.h,v 3.0 1992/10/21 16:56:19 pds Stab $
  23.  */
  24.  
  25. /*
  26.  *      STANDARD SERIES INFOCOM INTERPRETER
  27.  */
  28.  
  29. #define VERSION     3
  30.  
  31. #include <stdio.h>
  32.  
  33. #ifdef USE_DBMALLOC
  34. #include <sys/types.h>
  35. #include "dbmalloc.h"
  36. #endif
  37.  
  38. /*
  39.  * Universal Type Definitions.
  40.  *
  41.  *  'byte'                  - 8 bits       ; unsigned.
  42.  *  'word'                  - 16 bits      ; unsigned.
  43.  *  'signed_word'           - 16 bits      ; signed.
  44.  *  'long_word'             - 32 bits      ; signed.
  45.  */
  46.  
  47. #define         byte            unsigned char
  48. #define         word            unsigned short
  49. #define         signed_word     short
  50. #define         long_word       long
  51.  
  52. /*
  53.  * Constants
  54.  */
  55. #ifndef MAXPATHLEN
  56. #define         MAXPATHLEN              1024
  57. #endif
  58.  
  59. #define         LOCAL_VARS              0x10
  60. #define         STACK_SIZE              0x0200
  61. #define         BLOCK_SIZE              0x0200
  62. #define         MAX_MEM                 0xFFFF
  63.  
  64. /*
  65.  * Game State Codes
  66.  */
  67.  
  68. #define         NOT_INIT                0x00 /* Must be 0 */
  69. #define         INIT_GAME               0x01
  70. #define         PLAY_GAME               0x02
  71. #define         RESTART_GAME            0x03
  72. #define         LOAD_GAME               0x04
  73. #define         QUIT_GAME               0x05
  74.  
  75. /*
  76.  * scr_*_sf() Type Codes
  77.  */
  78.  
  79. #define         SF_SAVE                 0x00
  80. #define         SF_RESTORE              0x01
  81. #define         SF_SCRIPT               0x02
  82.  
  83. /*
  84.  * ANSI C compatibility stuff
  85.  */
  86.  
  87. #if defined(__STDC__) || defined(__TURBOC__)
  88.  
  89. typedef void *  ptr_t;
  90. #define P(s)    s
  91.  
  92. #define A1(t,v) (t v)
  93. #define A2(t1,v1,t2,v2) \
  94.                 (t1 v1,t2 v2)
  95. #define A3(t1,v1,t2,v2,t3,v3) \
  96.                 (t1 v1,t2 v2,t3 v3)
  97. #define A4(t1,v1,t2,v2,t3,v3,t4,v4) \
  98.                 (t1 v1,t2 v2,t3 v3,t4 v4)
  99. #define A5(t1,v1,t2,v2,t3,v3,t4,v4,t5,v5) \
  100.                 (t1 v1,t2 v2,t3 v3,t4 v4,t5 v5)
  101. #define A6(t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6) \
  102.                 (t1 v1,t2 v2,t3 v3,t4 v4,t5 v5,t6 v6)
  103.  
  104. #else
  105.  
  106. typedef char *  ptr_t;
  107.  
  108. #if !defined(sun)
  109. #define void    int
  110. #endif
  111.  
  112. #define const
  113. #define P(s)    ()
  114.  
  115. #define A1(t,v) (v) t v;
  116. #define A2(t1,v1,t2,v2) \
  117.                 (v1,v2)t1 v1;t2 v2;
  118. #define A3(t1,v1,t2,v2,t3,v3) \
  119.                 (v1,v2,v3)t1 v1;t2 v2;t3 v3;
  120. #define A4(t1,v1,t2,v2,t3,v3,t4,v4) \
  121.                 (v1,v2,v3,v4)t1 v1;t2 v2;t3 v3;t4 v4;
  122. #define A5(t1,v1,t2,v2,t3,v3,t4,v4,t5,v5) \
  123.                 (v1,v2,v3,v4,v5)t1 v1;t2 v2;t3 v3;t4 v4;t5 v5;
  124. #define A6(t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6) \
  125.                 (v1,v2,v3,v4,v5,v6)t1 v1;t2 v2;t3 v3;t4 v4;t5 v5;t6 v6;
  126.  
  127. #endif
  128.  
  129. /*
  130.  * Bitfield Macros:
  131.  *
  132.  * These macros modify the flag bits; they should be used instead of
  133.  * direct bit-twiddling for the header flags fields.  They may only be
  134.  * used after init() has been called.
  135.  */
  136. #define F1_IS_SET(_b)   (base_ptr[1]&(_b))
  137. #define F1_SETB(_b)     (base_ptr[1]|=(_b))
  138. #define F1_RESETB(_b)   (base_ptr[1]&=(~(_b)))
  139.  
  140. #define F2_IS_SET(_b)   (base_ptr[17]&(_b))
  141. #define F2_SETB(_b)     (base_ptr[17]|=(_b))
  142. #define F2_RESETB(_b)   (base_ptr[17]&=(~(_b)))
  143.  
  144. /*
  145.  * These are possible bits to be examine in header.flags_1:
  146.  */
  147. #define B_USE_TIME      (0x02)              /* Readonly */
  148. #define B_TANDY         (0x08)
  149. #define B_ALT_PROMPT    (0x10)
  150. #define B_STATUS_WIN    (0x20)
  151.  
  152. /*
  153.  * These are possible bits to examine in header.flags_2:
  154.  */
  155. #define B_SCRIPTING     (0x01)
  156. #define B_FIXED_FONT    (0x02)
  157. #define B_SOUND         (0x10)
  158.  
  159.  
  160. /*
  161.  * Conversion Macros:
  162.  *
  163.  * These macros convert from data file info into the current machine's
  164.  * byte order, etc.
  165.  */
  166. #define Z_TO_BYTE(_p)   ((byte)((_p)[0]&0xff))
  167. #define Z_TO_WORD(_p)   ((word)((((_p)[0]&0xff)<<8)+((_p)[1]&0xff)))
  168.  
  169. #define Z_TO_BYTE_I(_p) ((byte)(*(_p++)&0xff))
  170. #define Z_TO_WORD_I(_p) ((_p)+=2,((word)(((_p)[-2]&0xff)<<8)+((_p)[-1]&0xff)))
  171.  
  172. /*
  173.  * Speed Macros:
  174.  *
  175.  * These macro-ize certain bottlenecks (discovered using the UNIX
  176.  * utility prof(1)).  Use NEXT_BYTE() like a function returning void.
  177.  */
  178. #define NEXT_BYTE(_v) do{ extern word pc_offset; extern byte *prog_block_ptr;\
  179.                           (_v)=Z_TO_BYTE(prog_block_ptr+pc_offset++);\
  180.                           if(pc_offset==BLOCK_SIZE)fix_pc(); }while (0)
  181.  
  182. /*
  183.  * Type Definitions
  184.  */
  185.  
  186. typedef int     Bool;
  187. typedef byte    *property;
  188.  
  189. /*
  190.  * Global Flags Structure
  191.  *
  192.  * Contains flags and other information used globally by both the
  193.  * interpreter and the terminal interface.
  194.  */
  195. typedef struct gflags
  196. {
  197.     const char  *filenm;                    /* Game file name */
  198.     int         game_state;                 /* Game state */
  199.     Bool        pr_attr;                    /* Print obj attr assignments */
  200.     Bool        pr_atest;                   /* Print obj attr tests */
  201.     Bool        pr_xfers;                   /* Print obj location xfers */
  202.     Bool        pr_status;                  /* Print status line */
  203.     Bool        paged;                      /* Page long output */
  204.     Bool        echo;                       /* Echo input lines */
  205. } gflags_t;
  206.  
  207. /*
  208.  * File Information Structure
  209.  *
  210.  * This structure contains various interesing bits of information
  211.  * related to the file we're examining.
  212.  */
  213. typedef struct file
  214. {
  215.     word    pages;
  216.     word    offset;
  217. } file_t;
  218.  
  219. /*
  220.  * Object Structure Definition.
  221.  *
  222.  * Since version 4/5/6 objects are a different size than version 3
  223.  * objects, we define both styles here.  The obj_addr() function will
  224.  * use the information in the obj_info_t structure to find the object
  225.  * list correctly.
  226.  *
  227.  * The interpreter code assumes ver. 3 style objects, but the higher
  228.  * versions are understood for object listings.
  229.  */
  230. typedef struct obj_info
  231. {
  232.     byte    *obj_base;                      /* Start of obj table */
  233.     int     obj_size;                       /* Size of each obj entry */
  234.     int     obj_offset;                     /* start of objs */
  235.     int     is_eobj;                        /* 0==v3 obj : 1==v4,5,6 obj */
  236. } obj_info_t;
  237.  
  238. typedef struct object
  239. {
  240.     byte    attributes[4];
  241.     byte    parent;
  242.     byte    sibling;
  243.     byte    child;
  244.     byte    data[2];
  245. } object_t;
  246.  
  247. typedef struct eobject
  248. {
  249.     byte    attributes[6];
  250.     byte    parent[2];
  251.     byte    sibling[2];
  252.     byte    child[2];
  253.     byte    data[2];
  254. } eobject_t;
  255.  
  256. /*
  257.  * Print Buffer Structure
  258.  *
  259.  *  buf     Points to the buffer to be filled in
  260.  *  len     Current length of filled-in data
  261.  *  max     The maximum size of the buffer (not including the nul char)
  262.  */
  263. typedef struct print_buf
  264. {
  265.     byte    *buf;
  266.     int     len;
  267.     int     max;
  268. } print_buf_t;
  269.  
  270. /*
  271.  * Infocom Game Header Structure
  272.  *
  273.  *  The 'z_version' byte has the following meaning:
  274.  *      00 : Game compiled for an early version of the interpreter
  275.  *      01 : Game compiled for an early version of the interpreter
  276.  *      02 : Game compiled for an early version of the interpreter
  277.  *      03 : Standard Series Interpreter
  278.  *      04 : Plus Series Interpreter
  279.  *      05 : Solid Gold Interactive Fiction
  280.  *      06 : Graphic Interactive Fiction
  281.  *
  282.  *  The 'flags_1' byte contains the following information:
  283.  *      Bit #   Usage                   CLEAR       SET
  284.  *      -----   ---------------------   -----       -----
  285.  *        0     Game Header             OK          Error
  286.  *        1     Status Bar display      SCORE       TIME
  287.  *        5     Save file indicator      ??          ??
  288.  *
  289.  *  The 'flags_2' word is used by Z-CODE to set printing modes
  290.  *  for use by the interpreter:
  291.  *      Bit #   Usage                   CLEAR       SET
  292.  *      -----   ---------------------   -----       -----
  293.  *       0      Script mode             OFF         ON
  294.  *       1      Font type               -any-       fixed-width
  295.  *       4      Sound                   NO          YES
  296.  */
  297.  
  298. typedef struct header
  299. {
  300.         byte    z_version;              /* Game's Z-CODE Version Number    */
  301.         byte    flags_1;                /* Status indicator flags          */
  302.         word    release;                /* Game Release Number             */
  303.         word    resident_bytes;         /* No. bytes in the Resident Area  */
  304.         word    game_o;                 /* Offset to Start of Game         */
  305.         word    vocab_o;                /* Offset to Vocab List            */
  306.         word    object_o;               /* Offset to Object/Room List      */
  307.         word    variable_o;             /* Offset to Global Variables      */
  308.         word    save_bytes;             /* No. bytes in the Save Game Area */
  309.         word    flags_2;                /* Z-CODE printing modes           */
  310.         char    serial_no[6];           /* Game's Serial Number            */
  311.         word    common_word_o;          /* Offset to Common Word List      */
  312.         word    verify_length;          /* No. words in the Game File      */
  313.         word    verify_checksum;        /* Game Checksum - used by Verify  */
  314.         word    padding1[8];
  315.         word    fkey_o;                 /* Fkey offset (?)                 */
  316.         word    padding2[2];
  317.         word    alphabet_o;             /* Offset of alternate alphabets   */
  318.         word    padding3[5];
  319. } header_t;
  320.  
  321. /*
  322.  * Global Variables
  323.  */
  324.  
  325. extern obj_info_t   objd;
  326. extern gflags_t     gflags;
  327. extern byte *       base_ptr;
  328.  
  329. /*
  330.  * Function Prototypes
  331.  */
  332.  
  333. #define E extern
  334.  
  335. /*
  336.  * file.c
  337.  */
  338. E void          f_error P((int, const char *, const char *));
  339. E void          read_header P((header_t *));
  340. E const char *  open_file P((const char *));
  341. E void          close_file P((void));
  342. E void          load_page P((word, word, byte *));
  343. E void          save P((void));
  344. E void          restore P((void));
  345. /*
  346.  * funcs.c
  347.  */
  348. E void          plus P((word, word));
  349. E void          minus P((word, word));
  350. E void          multiply P((word, word));
  351. E void          divide P((word, word));
  352. E void          mod P((word, word));
  353. E void          pi_random P((word));
  354. E void          LTE P((word, word));
  355. E void          GTE P((word, word));
  356. E void          bit P((word, word));
  357. E void          or P((word, word));
  358. E void          not P((word));
  359. E void          and P((word, word));
  360. E void          compare P((word, const word *));
  361. E void          cp_zero P((word));
  362. /*
  363.  * infocom.c
  364.  */
  365. E void          seed_random P((void));
  366. /*
  367.  * init.c
  368.  */
  369. E void          init P((void));
  370. /*
  371.  * input.c
  372.  */
  373. E void          ti_escape P((char *));
  374. E void          input P((word, word));
  375. /*
  376.  * interp.c
  377.  */
  378. E void          interp P((void));
  379. /*
  380.  * jump.c
  381.  */
  382. E void          gosub P((word, const word *));
  383. E void          rtn P((word));
  384. E void          jump P((word));
  385. E void          rts P((void));
  386. E void          pop_stack P((void));
  387. /*
  388.  * object.c
  389.  */
  390. E void          transfer P((word, word));
  391. E void          remove_obj P((word));
  392. E void          test_attr P((word, word));
  393. E void          set_attr P((word, word));
  394. E void          clr_attr P((word, word));
  395. E void          get_loc P((word));
  396. E void          get_holds P((word));
  397. E void          get_link P((word));
  398. E void          check_loc P((word, word));
  399. E object_t *    obj_addr P((word));
  400. /*
  401.  * options.c
  402.  */
  403. E void          check_version P((void));
  404. E void          options P((Bool, Bool, Bool, Bool, Bool));
  405. /*
  406.  * page.c
  407.  */
  408. E void          pg_init P((void));
  409. E byte *        fetch_page P((word));
  410. E void          fix_pc P((void));
  411. /*
  412.  * print.c
  413.  */
  414. E const char *  chop_buf P((const char *, int));
  415. E void          print_init P((void));
  416. E void          print_num P((word));
  417. E char *        print_hnum P((word));
  418. E void          print_str P((const char *));
  419. E void          print2 P((word));
  420. E void          print1 P((word));
  421. E void          p_obj P((word));
  422. E void          wrt P((void));
  423. E void          writeln P((void));
  424. E void          new_line P((void));
  425. E void          print_char P((word));
  426. E void          prt_coded P((word *, word *));
  427. E void          decode P((word));
  428. E void          set_score P((void));
  429. /*
  430.  * property.c
  431.  */
  432. E void          next_prop P((word, word));
  433. E void          put_prop P((word, word, word));
  434. E void          get_prop P((word, word));
  435. E void          get_prop_addr P((word, word));
  436. E void          get_prop_len P((word));
  437. E void          load_word_array P((word, word));
  438. E void          load_byte_array P((word, word));
  439. E void          save_word_array P((word, word, word));
  440. E void          save_byte_array P((word, word, word));
  441. /*
  442.  * support.c
  443.  */
  444. E ptr_t         xmalloc P((unsigned int));
  445. E ptr_t         xrealloc P((ptr_t, unsigned int));
  446. E void          null P((void));
  447. E void          change_status P((void));
  448. E void          restart P((void));
  449. E void          quit P((void));
  450. E Bool          do_verify P((void));
  451. E void          verify P((void));
  452. E void          store P((word));
  453. E void          ret_value P((word));
  454. E void          error P((const char *, int));
  455. E void          askq P((int));
  456. E byte          get_byte P((word *, word *));
  457. E word          get_word P((word *, word *));
  458. E word          next_word P((void));
  459. /*
  460.  * variable.c
  461.  */
  462. E void          get_var P((word));
  463. E word          load_var P((word));
  464. E void          put_var P((word, word));
  465. E void          push P((word));
  466. E void          pop P((word));
  467. E void          inc_var P((word));
  468. E void          dec_var P((word));
  469. E void          inc_chk P((word, word));
  470. E void          dec_chk P((word, word));
  471. E word          load P((int));
  472. /*
  473.  * Terminal interface functions
  474.  */
  475. E int           scr_cmdarg P((int, char ***));
  476. E void          scr_getopt P((int, const char *));
  477. E int           scr_setup P((int, int, int, int));
  478. E void          scr_begin P((void));
  479. E void          scr_putline P((const char *));
  480. E void          scr_putscore P((void));
  481. E void          scr_putsound P((int, int, int, int));
  482. E void          scr_putmesg P((const char *, Bool));
  483. E int           scr_getline P((const char *, int, char *));
  484. E void          scr_window P((int));
  485. E void          scr_set_win P((int));
  486. E FILE *        scr_open_sf P((int, char *, int));
  487. E void          scr_close_sf P((const char *, FILE *, int));
  488. E void          scr_end P((void));
  489. E void          scr_shutdown P((void));
  490.  
  491. #undef E
  492.